package demo.java.java8.Lambdas.demo5;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import com.google.common.primitives.Ints;

import demo.java.java8.Lambdas.demo4.Dish;

public class Test {
	
	public static List<Dish> menu =  Arrays.asList(
			new Dish("pork", false, 800, Dish.Type.MEAT),
			new Dish("beef", false, 700, Dish.Type.MEAT),
			new Dish("chicken", false, 400, Dish.Type.MEAT),
			new Dish("french", true, 530, Dish.Type.OTHER),
			new Dish("rice", true, 350, Dish.Type.OTHER),
			new Dish("season", true, 120, Dish.Type.OTHER),
			new Dish("pizza", true, 550, Dish.Type.OTHER),
			new Dish("prawns", false, 300, Dish.Type.PISH),
			new Dish("salmon", false, 450, Dish.Type.PISH) );
	
	public static List<Integer> number = Arrays.asList(1,2,3,4,5);
	public static List<String> words= Arrays.asList("Java 8", "Lambdas", "In", "Action");
	

	public static void main(String[] args) {
		Stream<int[]> pythagoreanTriples=IntStream.rangeClosed(1, 100).boxed()
				.flatMap(a ->
						IntStream.rangeClosed(a, 100)
						.filter(b -> Math.sqrt(a*a + b*b) % 1==0)
						.mapToObj(b -> new int[]{a,b,(int)Math.sqrt(a*a + b*b)})
						);
		pythagoreanTriples.limit(5)
		.forEach(t -> System.out.println(t[0]+", "+t[1]+", "+t[2]));
		
//		IntStream evenNumbers=IntStream.rangeClosed(1, 100).filter(n -> n %2  ==0);
//		System.out.println(evenNumbers.count());
		
//		OptionalInt max = menu.stream().mapToInt(Dish::getCalories).max();
//		System.out.println(max);
		
//		IntStream calories=menu.stream().mapToInt(Dish::getCalories);
//		Stream<Integer> boxed = calories.boxed();
		
//		int calories=menu.stream().mapToInt(Dish::getCalories).sum();
//		System.out.println(calories);
		
		
//		int count = menu.stream().map(d ->1).reduce(0, (a,b) -> a+b);
//		int count = (int) menu.stream().count();
//		System.out.println(count);
		
		
//		int sum = number.stream().reduce(0, (a,b) -> a+b);
//		int sum = number.stream().reduce(0, Integer::sum);
//		int sum = number.stream().reduce(0, Integer::min);
//		int sum = number.stream().reduce(0, Integer::max);
//		System.out.println(sum);
		
//		Optional<Integer> firstSquareDivisibleByThree=number.stream().map(x -> x * x )
//				.filter(x -> x % 3==0)
//				.findAny();
//		System.out.println(firstSquareDivisibleByThree);
		
//		List<Integer> squares=number.stream().map(n -> n * n)
//		.collect(Collectors.toList());
//		System.out.println(squares);
//
//		List<Integer> wordsLengs=words.stream().map(String::length).collect(toList());
//
//		words.stream().map(word -> word.split("")).map(Arrays::stream).distinct().collect(toList());
//		
//		System.out.println(wordsLengs);
//		
//		
//		List<String> uniqueCharacters = words.stream().map(w -> w.split(""))
//				.flatMap(Arrays::stream).distinct().collect(Collectors.toList());
//		System.out.println(uniqueCharacters);
//		
//		List<Integer> number1 = Arrays.asList(1,2,3);
//		List<Integer> number2 = Arrays.asList(4,5);
//		
//		List<int[]> pairs=number1.stream().flatMap(
//				i -> number2.stream().filter(j -> (i+j)%3==0).map(j -> new int[]{i,j})
//				
//				).collect(Collectors.toList());
//		System.out.println(pairs);
	}


}
